Java Programming (Oracle Press) by Sarang Poornachandra
Author: Sarang, Poornachandra [Sarang, Poornachandra] , Date: September 14, 2017
, Views: 244
The dumpStack method receives a parameter of type Stack<Number>. Note the parameter specified in the type declaration. Because NumberStack is a generic type, we specify the data type on which the NumberStack will operate. Because Number is the least common superclass of all the real types used in our NumberStack class definition, we use Number in the parameter declaration. Thus, we should be able to pass on a NumberStack object of any type to the dumpStack method. Wait a minute! This is not quite true, as you’ll see shortly.
Now, let’s instantiate the NumberStack class with Number as the real type and push a Long number on it:
Copyright Disclaimer:
This site does not store any files on its server. We only index and link
to content provided by other sites. Please contact the content providers
to delete copyright contents if any and email us, we'll remove relevant
links or contents immediately.